package ihm.model;

import java.util.List;

import service.BalanceMonthService;
import service.PaymentService;

import domain.BalanceMonth;
import domain.Payment;

public class PaymentModel {
	
	private List<Payment> payments;
	private BalanceMonth balanceMonth;
	
	public PaymentModel(BalanceMonth balanceMonth) {
		if (balanceMonth != null) {
			balanceMonth = BalanceMonthService.getInstance().getCurrentBalanceMonth();
		}
		PaymentService.getInstance().getAllByBalanceMonth(balanceMonth.getId());
	}

	/**
	 * @return the payments
	 */
	public List<Payment> getPayments() {
		return payments;
	}
	
	public void addPayment(Payment payment) {
		payments.add(payment);
	}

	public Payment getPayment(Integer id) {
		for (Payment payment : payments) {
			if (payment.getId().equals(id)) {
				return payment;
			}
		}
		return null;
	}
	
	public void reset() {
		PaymentService.getInstance().getAllByBalanceMonth(balanceMonth.getId());
	}
}
